import { color } from "cc";

export const Colors = {
    0: color().fromHEX('#555555'),
    1: color().fromHEX('#ff5343'), // 红
    2: color().fromHEX('#7ee722'), // 草绿
    3: color().fromHEX('#ffd02d'), // 黄
    4: color().fromHEX('#4366ff'), // 蓝
    5: color().fromHEX('#ff6f9b'), // 玫色
    6: color().fromHEX('#ff9039'), // 橙
    7: color().fromHEX('#6879ac'), // 深蓝
    8: color().fromHEX('#2ad5f9'), // 青
    9: color().fromHEX('#d959ff'), // 紫

    10: color().fromHEX('#32712c'), // 祖母绿
    11: color().fromHEX('#34abb0'), //浅蓝
    12: color().fromHEX('#916d2a'), //土黄
    13: color().fromHEX('#398dd8'), //天蓝
    14: color().fromHEX('#799728'), //青绿
    15: color().fromHEX('#194f5e'), //肉
}

export enum CellType {
    Empty = 0, // 空位
    Block = 1, // 可操作的积木
    Glass = 2, // 玻璃
}

export type BlockType = {
    id: number,
    pos: number,
    shape: number,
    color: number,
}

export type GlassType = {
    id: number,
    pos: number,
    shape: number,
    nails: number[],
    layer: number, // 顺序，数值越大越靠前面
    lock: number, // 锁定值
}

export type StageInfo = {
    stageId: number;
    width: number;
    height: number;
    blocks: BlockType[];
    glasses: GlassType[];
    hard?: number;
}

export const dirArrowTxt = ['→', '↑', '←', '↓'];

export type ShapeInfo = {
    shapeId?: number,
    data: number[][],
    tex: string[], // 图片编号组
    size?: number[], // 最大矩形外边框 [行数,列数]
    center?: number[], // 中心点格号 (可能出现半格)
}

export const shapeInfoMap = new Map<number, ShapeInfo>([
    [0, {
        data: [],
        tex: [],
    }],
    [1, {
        data: [[0, 0]],
        tex: ['0000|0'],
    }],
    [2, {
        data: [[0, 0], [0, 1]],
        tex: ['0011|1', '0011|3'],
    }],
    [3, {
        data: [[0, 0], [1, 0]],
        tex: ['0011|0', '0011|2'],
    }],
    [4, {
        data: [[0, 0], [0, 1], [0, 2]],
        tex: ['0011|1', '1111|0', '0011|3'],
    }],
    [5, {
        data: [[0, 0], [1, 0], [2, 0]],
        tex: ['0011|0', '1111|0', '0011|2'],
    }],
    [6, {
        data: [[0, 0], [0, 1], [1, 0]],
        tex: ['0111|1', '0011|3', '0011|2'],
    }],
    [7, {
        data: [[0, 0], [1, 0], [1, 1]],
        tex: ['0011|0', '0111|2', '0011|3'],
    }]
]);

for (let [shapeId, shapeInfo] of shapeInfoMap) {
    shapeInfo.shapeId = shapeId;
    let size = [0, 0];
    for (let i = 0; i < shapeInfo.data.length; i++) {
        let dataItem = shapeInfo.data[i];
        if (dataItem[0] + 1 > size[0]) size[0] = dataItem[0] + 1;
        if (dataItem[1] + 1 > size[1]) size[1] = dataItem[1] + 1;
    }
    shapeInfo.size = size;
    shapeInfo.center = [(size[0] - 1) / 2, (size[1] - 1) / 2];
}